from django.contrib import admin

# Register your models here.
from ormapp.models import BookInfo, HeroInfo

# 内联英雄的管理器
class HeroInfoStackInline(admin.StackedInline):
    model = HeroInfo  # 要编辑的对象
    extra = 1  # 附加编辑的数量

class HeroInfoTabularInline(admin.TabularInline):
    model = HeroInfo
    extra = 1

# 图书的管理类
class BookInfoAdmin(admin.ModelAdmin):
    ###
    # 列表页设置
    # 列表页要展示的列
    list_display = ['id', 'btitle', 'bpub_date', 'bread', 'bcomment', 'is_hot', 'is_delete']
    # 每页展示数量
    list_per_page = 3
    # 操作选项是否在顶部显示
    actions_on_top = False
    # 操作选项是否在底部显示
    actions_on_bottom = True
    # 右侧过滤器, 筛选
    list_filter = ['is_delete']
    # 搜索框
    search_fields = ['btitle', 'bread']


    ####
    # 编辑页设置
    # 显示的字段
    # fields = ['btitle', 'bpub_date','bread','bcomment']
    # 分组显示字段
    fieldsets = (
        ('基本', {'fields': ['btitle', 'bpub_date']}),
        ('高级', {
            'fields': ['bread', 'bcomment','image', 'is_delete'],
            'classes': ('collapse',)  # 是否折叠显示
        })
    )

    inlines = [HeroInfoTabularInline]
    pass


# 英雄的管理类
class HeroInfoAdmin(admin.ModelAdmin):
    list_display = ['hname', 'hread']
    pass


admin.site.register(BookInfo, BookInfoAdmin)
admin.site.register(HeroInfo, HeroInfoAdmin)

admin.site.site_title = '传智书城MIS'

admin.site.site_header = '传智书城'

admin.site.index_title = '欢迎使用传智书城MIS'
